package com.dms.service;

import java.util.*;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import com.dms.dao.*;
import com.dms.model.*;
@Service
public class TeacherService {
	@Resource
	private TeacherDao dao;
	@Resource
	private BuildingService bService;
	public Teacher checkLogin(String username,String password){
		String hql="from Teacher where username='"
			+username+"' and password='"+password+"'";
//		System.out.println("TeacherService checkLogin hql"+hql);
		Teacher teacher=dao.getTeacher(hql);
		return teacher;
	}
	
	public Teacher getTeacher(int id){
		String hql="from Teacher where id="+id;
		return dao.getTeacher(hql);
	}
	
	public void updateTeacher(Teacher teacher) {
		dao.updateTeacher(teacher);
	}
	
	public List<Teacher> getTeacherList(){
		String hql="from Teacher";
		return dao.getTeachers(hql);
	}
	
	public List<Teacher> searchTeacher(String sKey,String sValue){
		String hql="from Teacher where "+sKey+"='"+sValue+"'";
//		System.out.println("searchTeacher hql="+hql);
		return dao.getTeachers(hql);
	}
	
	public void saveTeacher(Teacher teacher){
		dao.save(teacher);
	}
	
	public void deleteTeacher(int id){
		dao.delete(id);
	}
	
	public List<Teacher> getTeachersByBuilding(int bid){
		List<Teacher> list=new ArrayList<Teacher>();
		Building building=bService.getBuilding(bid);
		List<TB> tbs=building.getTBs();
		for(TB tb:tbs){
			list.add(tb.getTeacher());			
		}
		return list;
	}
	
}
